package NGUYENVANTHANG.arrayt6;



public class StudentController {

    /**
     * Nghiệp vụ sắp xếp thông tin sinh viên theo điểm
     * @param objStudent
     */
    public void StudentSort(StudentEntity[] objStudent) {
        for (int i = objStudent.length - 1; i >= 1; i--) {
            // Find the maximum in the list[0..i]
            StudentEntity currentScores = objStudent[0];
            int currentMaxIndex = 0;
            {
                for (int j = 1; j <= i; j++) {
                    if (currentScores.getScores() > objStudent[j].getScores()) {
                        currentScores = objStudent[j];
                        currentMaxIndex = j;
                    }
                }
                // Swap list[i] with list[currentMaxIndex] if necessary;
                if (currentMaxIndex != i) {
                    objStudent[currentMaxIndex] = objStudent[i];
                    objStudent[i] = currentScores;
                }
            }
        }
    }

    // Sort - Insertion Sort?
    public void StudentInsertionSort(StudentEntity[] objStudent) {
        for (int i = 1; i < objStudent.length; i++) {
            StudentEntity currentElement = objStudent[i];
            int k;
            for (k = i - 1; k >= 0 && objStudent[k].getScores() > currentElement.getScores(); k--) {
                objStudent[k + 1] = objStudent[k];
            }
            // Insert the current element into list[k+1]
            objStudent[k + 1] = currentElement;
        }
    }

    // Sort - Buggdy Sort?
    /***
     * Nghiệp vụ sắp xếp thông tin sinh viên theo điểm với Buggdy Sort
     * @param objStudent
     */
    public void StudentBuggdySort(StudentEntity[] objStudent) {
        for (int i = 0; i < objStudent.length; i++) {
            for (int j = i + 1; j < objStudent.length; j++) {
                if (objStudent[i].getScores() > objStudent[j].getScores()) {
                    StudentEntity temp = objStudent[i];
                    objStudent[i] = objStudent[j];
                    objStudent[j] = temp;
                }
            }
        }
    }

}
